﻿Imports System
Imports System.ComponentModel
Imports System.ComponentModel.Design
Imports System.Globalization
Imports System.Workflow.Activities.Rules
Imports System.Workflow.ComponentModel
Imports System.Workflow.ComponentModel.Design

Namespace System.Workflow.Activities.Rules.Design
    Friend MustInherit Class RuleDefinitionDynamicPropertyDescriptor
        Inherits DynamicPropertyDescriptor
        ' Methods
        Public Sub New(ByVal serviceProvider As IServiceProvider, ByVal descriptor As PropertyDescriptor)
            MyBase.New(serviceProvider, descriptor)
        End Sub

        Protected Function GetRuleDefinitions(ByVal component As Object) As RuleDefinitions
            Dim service As IReferenceService = DirectCast(MyBase.ServiceProvider.GetService(GetType(IReferenceService)), IReferenceService)
            If (service Is Nothing) Then
                Throw New InvalidOperationException(String.Format(CultureInfo.CurrentCulture, Messages.MissingService, New Object() { GetType(IReferenceService).FullName }))
            End If
            Dim activity As Activity = [TryCast](service.GetComponent(component),Activity)
            If (activity Is Nothing) Then
                Return Nothing
            End If
            Dim rootActivity As Activity = Helpers.GetRootActivity(activity)
            If (rootActivity Is Nothing) Then
                Return Nothing
            End If
            Dim declaringActivity As Activity = Helpers.GetDeclaringActivity(activity)
            If ((Not declaringActivity Is rootActivity) AndAlso (Not declaringActivity Is Nothing)) Then
                Return ConditionHelper.GetRuleDefinitionsFromManifest(declaringActivity.GetType)
            End If
            Return ConditionHelper.Load_Rules_DT(MyBase.ServiceProvider, rootActivity)
        End Function

    End Class
End Namespace

